package com.boot.app.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.boot.app.base.domain.BaseUser;
import com.boot.app.base.service.IBaseUserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootTest
public class ResetPassword {

    @Autowired
    private IBaseUserService userService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    void resetPassword(){
        String username = "test";
        LambdaQueryWrapper<BaseUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseUser::getUsername, username);
        BaseUser baseUser = userService.getOne(queryWrapper);
        ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
        String password = operations.get("PASSWORD.RESET");
        String encode = passwordEncoder.encode(password);
        baseUser.setPassword(encode);
        userService.updateById(baseUser);
//        userService.updateById(baseUser);
//        BaseUser uu = new BaseUser();
//        uu.setUsername("uuu");
//        userService.save(uu);
    }

}
